<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="部署和使用RocketMq">
<meta property="og:type" content="article">
<meta property="og:title" content="【RocketMq】使用Idea部署RocketMq 源代码（4.9.4）">
<meta property="og:url" content="https://whitestore.top/2023/03/11/rocketjianhua/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="部署和使用RocketMq">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826144547.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826151618.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826152001.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826151917.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826155828.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160028.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160215.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160352.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160453.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826164323.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826164712.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826173454.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826205432.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826215646.png">
<meta property="article:published_time" content="2023-03-10T23:24:00.000Z">
<meta property="article:modified_time" content="2023-06-15T13:10:39.212Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="RocketMq部署和简化">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826144547.png">

<link rel="canonical" href="https://whitestore.top/2023/03/11/rocketjianhua/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>【RocketMq】使用Idea部署RocketMq 源代码（4.9.4） | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2023/03/11/rocketjianhua/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【RocketMq】使用Idea部署RocketMq 源代码（4.9.4）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-03-11 07:24:00" itemprop="dateCreated datePublished" datetime="2023-03-11T07:24:00+08:00">2023-03-11</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-06-15 21:10:39" itemprop="dateModified" datetime="2023-06-15T21:10:39+08:00">2023-06-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/RocketMq/" itemprop="url" rel="index"><span itemprop="name">RocketMq</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/03/11/rocketjianhua/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/03/11/rocketjianhua/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.6k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>
            <div class="post-description">部署和使用RocketMq</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>#rocketmq  </p>
<h1 id="一、介绍"><a href="#一、介绍" class="headerlink" title="一、介绍"></a>一、介绍</h1><p>笔记为主，Idea部署RocketMq的简化流程。</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FwYWNoZS9yb2NrZXRtcQ==" title="https://github.com/apache/rocketmq">https://github.com/apache/rocketmq<i class="fa fa-external-link"></i></span></p>
<h1 id="二、提示"><a href="#二、提示" class="headerlink" title="二、提示"></a>二、提示</h1><h2 id="2-1-IDEA版本"><a href="#2-1-IDEA版本" class="headerlink" title="2.1 IDEA版本"></a>2.1 IDEA版本</h2><p>个人使用的Idea版本。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826144547.png" alt=""></p>
<a id="more"></a>

<h2 id="2-2-RocketMq源码版本"><a href="#2-2-RocketMq源码版本" class="headerlink" title="2.2 RocketMq源码版本"></a>2.2 RocketMq源码版本</h2><p>需要注意下载源代码之前，先检查一下自己的java版本，最低要求JDK1.8以上。</p>
<p>个人拉取的版本为 <strong>4.9.4</strong>，因为时效性未来版本有些代码可能会被改进，所以要注意版本问题。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">java version <span class="string">"1.8.0_341"</span></span><br><span class="line">Java(TM) <span class="function">SE Runtime <span class="title">Environment</span> <span class="params">(build <span class="number">1.8</span><span class="number">.0</span>_341-b10)</span></span></span><br><span class="line"><span class="function">Java <span class="title">HotSpot</span><span class="params">(TM)</span> 64-Bit Server <span class="title">VM</span> <span class="params">(build <span class="number">25.341</span>-b10, mixed mode)</span></span></span><br></pre></td></tr></table></figure>

<p>拉源码，这一步不需要过多介绍，直接点击主页右上角即可。</p>
<blockquote>
<p>这里从官方fork 了一下项目</p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826151618.png" alt=""></p>
<p>github 现在墙越来越厚，拉代码经常失败，没办法只能再套一层，用 gitee fork了一遍，双层套娃属于是。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826152001.png" alt=""></p>
<p>最后终于成功拉代码到本地（真不容易）。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826151917.png" alt=""></p>
<h1 id="三、操作步骤"><a href="#三、操作步骤" class="headerlink" title="三、操作步骤"></a>三、操作步骤</h1><h2 id="3-1-下载源代码"><a href="#3-1-下载源代码" class="headerlink" title="3.1 下载源代码"></a>3.1 下载源代码</h2><p>个人fork版本（4.9.9）：<span class="exturl" data-url="aHR0cHM6Ly9naXRlZS5jb20vbGF6eVRpbWVzL3JvY2tldG1xLWFkb25nLmdpdA==" title="https://gitee.com/lazyTimes/rocketmq-adong.git">https://gitee.com/lazyTimes/rocketmq-adong.git<i class="fa fa-external-link"></i></span></p>
<p>官方gituhb（最新版本）：<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FwYWNoZS9yb2NrZXRtcS5naXQ=" title="https://github.com/apache/rocketmq.git">https://github.com/apache/rocketmq.git<i class="fa fa-external-link"></i></span></p>
<p><strong>源码目录结构</strong>：</p>
<ul>
<li><strong>broker</strong>: broker 模块（broke 启动进程）</li>
<li><strong>client</strong> ：消息客户端，包含消息生产者、消息消费者相关类</li>
<li><strong>common</strong> ：公共包</li>
<li><strong>dev</strong> ：开发者信息（非源代码）</li>
<li><strong>distribution</strong> ：部署实例文件夹（非源代码）</li>
<li><strong>example</strong>: RocketMQ 例代码</li>
<li><strong>filter</strong> ：消息过滤相关基础类</li>
<li><strong>filtersrv</strong>：消息过滤服务器实现相关类（Filter启动进程）</li>
<li><strong>logappender</strong>：日志实现相关类</li>
<li><strong>namesrv</strong>：NameServer实现相关类（NameServer启动进程）</li>
<li><strong>openmessageing</strong>：消息开放标准</li>
<li><strong>remoting</strong>：远程通信模块，基于Netty</li>
<li><strong>srcutil</strong>：服务工具类</li>
<li><strong>store</strong>：消息存储实现相关类</li>
<li><strong>style</strong>：checkstyle相关实现</li>
<li><strong>test</strong>：测试相关类</li>
<li><strong>tools</strong>：工具类，监控命令相关实现类</li>
</ul>
<h2 id="3-2-检查Maven配置"><a href="#3-2-检查Maven配置" class="headerlink" title="3.2 检查Maven配置"></a>3.2 检查Maven配置</h2><p>拉下来之后不要急着调配置，我们先检查idea里面的Maven配置是否被重置，如果被重置了就改回来，另外最好检查一下当前使用的项目编译版本， IDEA 经常会用内置的JDK版本对项目编译，个人也因为这个问题浪费了不少时间。</p>
<p>总而言之，拉下项目做下面三件事：</p>
<ul>
<li>编译，检查是否报错</li>
<li>检查JDK版本</li>
<li>检查Maven配置，以及Maven所用JDK打包版本（在setting里可以看到）。</li>
<li>反复检查，确保无误。</li>
</ul>
<h2 id="3-3-设置NameServ"><a href="#3-3-设置NameServ" class="headerlink" title="3.3 设置NameServ"></a>3.3 设置NameServ</h2><p>首先是设置命名服务，这是Producer发送消息必要服务之一。</p>
<p>这一步核心步骤就两个：</p>
<ul>
<li>启动参数设置 <code>ROCKETMQ_HOME</code> ，如果不会设置就直接项目的根路径，但还是建议设置一个单独目录里面方便后续观察。</li>
<li>设置<code>logback_namesrv.xml</code>，它所在的路径必须跟 <code>ROCKETMQ_HOME</code> 相同，否则 <code>NameServ</code> 启动会报错。</li>
</ul>
<p>设置<code>ROCKETMQ</code>运行主目录，Mac系统和Window设置出来的路径不一样，个人使用Windows作为案例，所以设置的路径为：<code>E:\adongstack\project\selfUp\rocketmq-adong</code></p>
<ol>
<li>接着我们进入 NameSer 这个项目，直接跑<code>org.apache.rocketmq.namesrv.NamesrvStartup#main()</code>方法，不出意外会给一个提示：</li>
</ol>
<blockquote>
<p>Please set the ROCKETMQ_HOME variable in your environment to match the location of the RocketMQ installation</p>
</blockquote>
<p>日志非常简洁明了，要求设置 <code>ROCKETMQ_HOME</code>，但是要设置在哪里，怎么设置？</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826155828.png" alt=""></p>
<ol start="2">
<li>运行过一次<code>org.apache.rocketmq.namesrv.NamesrvStartup#main()</code>方法之后，Idea会有历史启动记录保留，这时候可以对于启动参数进行配置：</li>
</ol>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160028.png" alt=""></p>
<ol start="3">
<li>点击启动参数Env…..，然后在里面配置前文提到的<code>ROCKETMQ_HOME</code>，这里个人设置了独立路径，建议读者尝试的时候用一个单独的空文件目录，方便后期查找。</li>
</ol>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160215.png" alt=""></p>
<ol start="4">
<li>注意新版本IDEA的按钮位置变了，点击“+”号之后，填充参数。</li>
</ol>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160352.png" alt=""></p>
<ol start="5">
<li>确认之后，会发现下面的效果。然后继续运行<code>Main()</code>方法。</li>
</ol>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826160453.png" alt="路径配置结果"></p>
<p>但是很遗憾，还是报错，日志提示需要<code>logback_namesrv.xml</code>，实际上就是logback的日志配置文件，我们可以从源代码的<code>E:\adongstack\project\selfUp\rocketmq-adong\distribution\conf\logback_namesrv.xml</code>（个人路径为例）找到这个文件的配置。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826164323.png" alt=""></p>
<ol start="6">
<li>因为不知道文件放在哪里，我们尝试把项目的<code>logback_namesrv.xml</code>配置放到下面这个位置，看看什么效果。</li>
</ol>
<blockquote>
<p>logback的配置这里就不介绍了，可以自行查阅官方文档或者上网查查资料了解配置含义。</p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826164712.png" alt=""></p>
<p>然而这种配置方式<strong>是错的</strong>，实际上我们要移动配置到 <strong>ROCKETMQ_HOME</strong> 所在目录中。日志报错会引导我们进行正确改进。</p>
<ol start="7">
<li>最后尝试执行<code>org.apache.rocketmq.namesrv.NamesrvStartup#main()</code>方法，成功！打印内容如下。</li>
</ol>
<figure class="highlight console"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">The Name Server boot success. serializeType=JSON</span><br></pre></td></tr></table></figure>

<h2 id="3-4-设置Broker"><a href="#3-4-设置Broker" class="headerlink" title="3.4 设置Broker"></a>3.4 设置Broker</h2><p>Broker负责持久化队列消息，以及从NameServ 中寻找路由信息，Producer 借助NameServ 找到Broker之后会推送消息，Broker成功收到消息后通知Producer消息发送成功。</p>
<p>这一步设置比较关键，仔细观察配置。</p>
<p>设置Broker主要考虑两点，第一点是<code>broker.conf</code>配置，第二点是配置Broker的logback的xml日志文件。</p>
<p>接着我们设置 Broker ，Broker的启动入口在<code>src/main/java/org/apache/rocketmq/broker/BrokerStartup.java</code>，一上来我们先不急着改启动环境的参数，而是先把 Broker 的关键配置改了，<strong>主要设置 NameServer 的地址、Broker 的名称等相关属性</strong>，这些依赖配置文件<code>broker.conf</code>。</p>
<p>首先我们要先查自己本地回环网卡的IP地址（就是s你上网那张网卡的IP），比如我的IP是<code>192.168.0.6</code>。</p>
<p>有了IP之后，我们可以先备份一份<code>distribution/conf/broker.conf</code>文件，然后修改里面的配置：</p>
<blockquote>
<p>也可以直接复制一份<code>distribution/conf/broker.conf</code>配置到 <strong>ROCKETMQ_HOME</strong>然后再进行改动，这里仅仅是个人习惯问题，方便日后直接在项目里面立马可以看到自己定义的配置。</p>
</blockquote>
<p><code>broker.conf</code>官方给的默认配置：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">brokerClusterName &#x3D; DefaultCluster  </span><br><span class="line">brokerName &#x3D; broker-a  </span><br><span class="line">brokerId &#x3D; 0  </span><br><span class="line">deleteWhen &#x3D; 04  </span><br><span class="line">fileReservedTime &#x3D; 48  </span><br><span class="line">brokerRole &#x3D; ASYNC_MASTER  </span><br><span class="line">flushDiskType &#x3D; ASYNC_FLUSH</span><br></pre></td></tr></table></figure>

<p><code>broker.conf</code>修改之后的配置，注意有新增内容，个人命名为<code>broker-back.conf</code>：</p>
<blockquote>
<p>这些配置都可以从源代码的配置文件里面找到对应的参数属性。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"># 使用如下配置文件  </span><br><span class="line">brokerClusterName &#x3D; DefaultCluster  </span><br><span class="line">brokerName &#x3D; broker-a  </span><br><span class="line">brokerId &#x3D; 0  </span><br><span class="line">deleteWhen &#x3D; 04  </span><br><span class="line">fileReservedTime &#x3D; 48  </span><br><span class="line">brokerRole &#x3D; ASYNC_MASTER  </span><br><span class="line">flushDiskType &#x3D; ASYNC_FLUSH  </span><br><span class="line">storePathRootDir&#x3D;E:\\adongstack\\project\\selfUp\\rocketmq-adong\\tmp\\run-dev\\store  </span><br><span class="line">storePathCommitLog&#x3D;E:\\adongstack\\project\\selfUp\\rocketmq-adong\\tmp\\run-dev\\store\\commitlog  </span><br><span class="line"># 重点内容</span><br><span class="line">namesrvAddr&#x3D;127.0.0.1:9876  </span><br><span class="line">brokerIP1&#x3D;192.168.0.6  </span><br><span class="line">brokerIP2&#x3D;192.168.0.6  </span><br><span class="line">autoCreateTopicEnable&#x3D;true</span><br></pre></td></tr></table></figure>

<blockquote>
<p>为啥是 store 和 store\commitlog，一个是Broker的持久化仓库地址，一个是提交日志存储地址，这里建议分开，RocketMq的commitlog使用的是追加写入的方式。</p>
</blockquote>
<p>注意网上有一些教程的配置文件内容可能比这份文件要多一些，其实只是更加细化的配置而已，这些简单的配置足够我们调试最简单的源码。</p>
<p>修改完成之后，我们同样把<strong>distribution/conf/logback_brokerxml</strong> 以及 <strong>broker.conf</strong>拷贝到 <code>ROCKETMQ_HOME</code>当中。经过这么一番操作配置，最终结果如下：</p>
<blockquote>
<p>这里把所有的配置放到一个文件夹里面，方便管理，截图所属文件的根路径是<code>E:\adongstack\project\selfUp\rocketmq-adong\tmp\run-dev</code></p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826173454.png" alt=""></p>
<p>解剖路径如下：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># `E:\adongstack\project\selfUp\rocketmq-adong\tmp\run-dev`//.....</span></span><br><span class="line"><span class="meta">-</span> <span class="string">store</span></span><br><span class="line">	<span class="meta">-</span> <span class="string">commitlog</span></span><br><span class="line"><span class="meta">-</span> <span class="string">broker.conf</span></span><br><span class="line"><span class="meta">-</span> <span class="string">logback_broker.xml</span></span><br><span class="line"><span class="meta">-</span> <span class="string">logback_namesrv.xml</span></span><br></pre></td></tr></table></figure>

<p>最后，我们在<code>cc</code>的启动参数进行如下配置：</p>
<p><code>-c 启动参数</code> 对应conf配置文件。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-c E:\\adongstack\\project\\selfUp\\rocketmq-adong\\tmp\\run-dev\\broker.conf</span><br></pre></td></tr></table></figure>

<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826205432.png" alt="BrokerStartup启动参数"></p>
<p>最后再运行一遍<code>BrokerStartup</code>的main方法，出现下面的内容说明配置成功：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">The broker[broker-a, 192.168.0.103:10911] boot success. serializeType&#x3D;JSON and name server is 127.0.0.1:9876</span><br></pre></td></tr></table></figure>

<h2 id="3-5-运行测试"><a href="#3-5-运行测试" class="headerlink" title="3.5 运行测试"></a>3.5 运行测试</h2><p>首先我们把前面两个小节配置的NameServ和Broker的配置进行启动：</p>
<p>Broker 启动打印：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">The broker[broker-a, <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">10911</span>] boot success. serializeType=JSON and name server is <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9876</span></span><br></pre></td></tr></table></figure>

<p>NameServ 启动打印：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">The Name Server boot success. serializeType=JSON</span><br></pre></td></tr></table></figure>

<p>接着是使用Producer做测试，这里使用的是<code>org.apache.rocketmq.example.quickstart.Producer#main()</code>方法，注意这个案例是不能够直接拿来用的，因为我们使用debug模式，<strong>需要放开一行注释代码</strong>。</p>
<p>因为上面的所有配置都是使用官方推荐的默认配置，所以需要只需要放开这一段注释，默认连接的NameServ 端口是 9876。</p>
<blockquote>
<p>// Uncomment the following line while debugging, namesrvAddr should be set to your local address<br>  // 调试时取消注释以下行，namesrvAddr 应设置为您的本地地址，读者第一次看到这里应该是注释过的<br>  producer.setNamesrvAddr(DEFAULT_NAMESRVADDR);</p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20220826215646.png" alt=""></p>
<p>Producer的最终打印结果如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SendResult [sendStatus=SEND_OK, msgId=<span class="number">7F</span>000001858818B4AAC28569CA6C0000, offsetMsgId=<span class="number">7F</span>00000100002A9F00000000000000EF, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=<span class="number">0</span>], queueOffset=<span class="number">1</span>]</span><br><span class="line"><span class="number">21</span>:<span class="number">45</span>:<span class="number">02.846</span> [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9876</span>] result: <span class="keyword">true</span></span><br><span class="line"><span class="number">21</span>:<span class="number">45</span>:<span class="number">02.848</span> [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">10911</span>] result: <span class="keyword">true</span></span><br></pre></td></tr></table></figure>

<h1 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h1><p>IDEA 部署源代码整体流程比较简单，比较麻烦的反而是一些运行参数的配置上。另外github现在连接十分不稳定，建议用国内的一些代码管理网站进行同步，gitee、coding 都可以。</p>
<p>需要注意进行测试的时候一定要把注释放开，否则会一直出现Producer连不上的报错异常。</p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2023/03/11/rocketjianhua/" title="【RocketMq】使用Idea部署RocketMq 源代码（4.9.4）">https://whitestore.top/2023/03/11/rocketjianhua/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/RocketMq/" rel="tag"># RocketMq</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2023/03/11/shangyong/" rel="prev" title="【RocketMq】商用RocketMq和开源RocketMq的兼容问题解决方案">
      <i class="fa fa-chevron-left"></i> 【RocketMq】商用RocketMq和开源RocketMq的兼容问题解决方案
    </a></div>
      <div class="post-nav-item">
    <a href="/2023/03/11/rocketshengchanzhe/" rel="next" title="【RocketMq】Rocket 生产者相关知识点 - 消息发送者参数详解">
      【RocketMq】Rocket 生产者相关知识点 - 消息发送者参数详解 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#一、介绍"><span class="nav-number">1.</span> <span class="nav-text">一、介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、提示"><span class="nav-number">2.</span> <span class="nav-text">二、提示</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-IDEA版本"><span class="nav-number">2.1.</span> <span class="nav-text">2.1 IDEA版本</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-RocketMq源码版本"><span class="nav-number">2.2.</span> <span class="nav-text">2.2 RocketMq源码版本</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、操作步骤"><span class="nav-number">3.</span> <span class="nav-text">三、操作步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1-下载源代码"><span class="nav-number">3.1.</span> <span class="nav-text">3.1 下载源代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2-检查Maven配置"><span class="nav-number">3.2.</span> <span class="nav-text">3.2 检查Maven配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-设置NameServ"><span class="nav-number">3.3.</span> <span class="nav-text">3.3 设置NameServ</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-4-设置Broker"><span class="nav-number">3.4.</span> <span class="nav-text">3.4 设置Broker</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-5-运行测试"><span class="nav-number">3.5.</span> <span class="nav-text">3.5 运行测试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#小结"><span class="nav-number">4.</span> <span class="nav-text">小结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
